#region License

// Copyright (c) 2013, ClearCanvas Inc.
// All rights reserved.
// http://www.clearcanvas.ca
//
// This file is part of the ClearCanvas RIS/PACS open source project.
//
// The ClearCanvas RIS/PACS open source project is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// The ClearCanvas RIS/PACS open source project is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the ClearCanvas RIS/PACS open source project.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

// This file is auto-generated by the ClearCanvas.Model.SqlServer.CodeGenerator project.

namespace ClearCanvas.ImageServer.Model
{
    using System;
    using System.Xml;
    using ClearCanvas.Dicom;
    using ClearCanvas.Enterprise.Core;
    using ClearCanvas.ImageServer.Enterprise;
    using ClearCanvas.ImageServer.Enterprise.Command;
    using ClearCanvas.ImageServer.Model.EntityBrokers;

    [Serializable]
    public partial class Patient: ServerEntity
    {
        #region Constructors
        public Patient():base("Patient")
        {}
        public Patient(
             ServerEntityKey _serverPartitionKey_
            ,Int32 _numberOfPatientRelatedStudies_
            ,Int32 _numberOfPatientRelatedSeries_
            ,Int32 _numberOfPatientRelatedInstances_
            ,String _specificCharacterSet_
            ,String _patientsName_
            ,String _patientId_
            ,String _issuerOfPatientId_
            ):base("Patient")
        {
            ServerPartitionKey = _serverPartitionKey_;
            NumberOfPatientRelatedStudies = _numberOfPatientRelatedStudies_;
            NumberOfPatientRelatedSeries = _numberOfPatientRelatedSeries_;
            NumberOfPatientRelatedInstances = _numberOfPatientRelatedInstances_;
            SpecificCharacterSet = _specificCharacterSet_;
            PatientsName = _patientsName_;
            PatientId = _patientId_;
            IssuerOfPatientId = _issuerOfPatientId_;
        }
        #endregion

        #region Public Properties
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="ServerPartitionGUID")]
        public ServerEntityKey ServerPartitionKey
        { get; set; }
        [DicomField(DicomTags.NumberOfPatientRelatedStudies, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="NumberOfPatientRelatedStudies")]
        public Int32 NumberOfPatientRelatedStudies
        { get; set; }
        [DicomField(DicomTags.NumberOfPatientRelatedSeries, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="NumberOfPatientRelatedSeries")]
        public Int32 NumberOfPatientRelatedSeries
        { get; set; }
        [DicomField(DicomTags.NumberOfPatientRelatedInstances, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="NumberOfPatientRelatedInstances")]
        public Int32 NumberOfPatientRelatedInstances
        { get; set; }
        [DicomField(DicomTags.SpecificCharacterSet, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="SpecificCharacterSet")]
        public String SpecificCharacterSet
        { get; set; }
        [DicomField(DicomTags.PatientsName, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="PatientsName")]
        public String PatientsName
        { get; set; }
        [DicomField(DicomTags.PatientId, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="PatientId")]
        public String PatientId
        { get; set; }
        [DicomField(DicomTags.IssuerOfPatientId, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="Patient", ColumnName="IssuerOfPatientId")]
        public String IssuerOfPatientId
        { get; set; }
        #endregion

        #region Static Methods
        static public Patient Load(ServerEntityKey key)
        {
            using (var context = new ServerExecutionContext())
            {
                return Load(context.ReadContext, key);
            }
        }
        static public Patient Load(IPersistenceContext read, ServerEntityKey key)
        {
            var broker = read.GetBroker<IPatientEntityBroker>();
            Patient theObject = broker.Load(key);
            return theObject;
        }
        static public Patient Insert(Patient entity)
        {
            using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                Patient newEntity = Insert(update, entity);
                update.Commit();
                return newEntity;
            }
        }
        static public Patient Insert(IUpdateContext update, Patient entity)
        {
            var broker = update.GetBroker<IPatientEntityBroker>();
            var updateColumns = new PatientUpdateColumns();
            updateColumns.ServerPartitionKey = entity.ServerPartitionKey;
            updateColumns.NumberOfPatientRelatedStudies = entity.NumberOfPatientRelatedStudies;
            updateColumns.NumberOfPatientRelatedSeries = entity.NumberOfPatientRelatedSeries;
            updateColumns.NumberOfPatientRelatedInstances = entity.NumberOfPatientRelatedInstances;
            updateColumns.SpecificCharacterSet = entity.SpecificCharacterSet;
            updateColumns.PatientsName = entity.PatientsName;
            updateColumns.PatientId = entity.PatientId;
            updateColumns.IssuerOfPatientId = entity.IssuerOfPatientId;
            Patient newEntity = broker.Insert(updateColumns);
            return newEntity;
        }
        #endregion
    }
}
